home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 22 / CU Amiga Magazine's Super CD-ROM 22 (1998)(EMAP Images)(GB)[!][issue 1998-05].iso / PowerPC / System / PPCReleaseDEV / Examples / Msg4.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-02-21  |  4.3 KB  |  158 lines

  1. /* This test program sends 1000 messages to the M68k and
  2.    shows how long this takes.
  3.    The Messages are send synchron and every msg must
  4.    be replied after another.
  5.    Each Message has the Body "Text sent by PPC processor\n"
  6.  */
  7.  
  8. #include <exec/types.h>
  9. #include <exec/nodes.h>
  10. #include <exec/lists.h>
  11. #include <exec/memory.h>
  12. #include <utility/tagitem.h>
  13. #include <powerup/ppclib/interface.h>
  14. #include <powerup/ppclib/message.h>
  15. #include <powerup/ppclib/tasks.h>
  16. #include <powerup/proto/ppc.h>
  17. #include <proto/exec.h>
  18. #include <proto/dos.h>
  19. #include <stdio.h>
  20. #include <string.h>
  21. #include "time.h"
  22. #include "time_protos.h"
  23.  
  24. #define    MSGCOUNT    1000
  25.  
  26. struct StartupData
  27. {
  28.     void    *MsgPort;
  29.     ULONG    MsgCount;
  30. };
  31.  
  32. extern struct Library    *SysBase;
  33.  
  34. int    main(void)
  35. {
  36. struct Library        *PPCLibBase;
  37. struct TagItem        MyTags[10];
  38. void            *M68kPort;
  39. void            *StartupMsg;
  40. void            *M68kMsg;
  41. void            *ElfObject;
  42. void            *Task;
  43. struct StartupData    *StartupData;
  44. void            *MyTimerObject;
  45. ULONG            i;
  46.  
  47.   printf("Opening ppc.library\n");
  48.   if (PPCLibBase = OpenLibrary("ppc.library", 44))
  49.   {
  50.     if (MyTimerObject=TimerCreateObject())
  51.     {
  52.       printf("Loading PPC object\n");
  53.       if (ElfObject=PPCLoadObject("PROGDIR:Msg4PPC.elf"))
  54.       {
  55.         MyTags[0].ti_Tag    =    TAG_DONE;
  56.         if (M68kPort = PPCCreatePort(MyTags))
  57.         {
  58.           if (StartupMsg = PPCCreateMessage(M68kPort, 0))
  59.           {
  60.             printf("Allocating StartupData\n");
  61.             if (StartupData = PPCAllocVec(sizeof(struct StartupData), MEMF_ANY))
  62.             {
  63.               StartupData->MsgPort    =    M68kPort;
  64.               StartupData->MsgCount    =    MSGCOUNT;
  65.  
  66.               printf("Creating PPC task\n");
  67.               MyTags[0].ti_Tag        =    PPCTASKTAG_STARTUP_MSG;
  68.               MyTags[0].ti_Data        =(ULONG) StartupMsg;
  69.  
  70.               MyTags[1].ti_Tag        =    PPCTASKTAG_STARTUP_MSGDATA;
  71.               MyTags[1].ti_Data    =(ULONG) StartupData;
  72.  
  73.               MyTags[2].ti_Tag        =    PPCTASKTAG_STARTUP_MSGLENGTH;
  74.               MyTags[2].ti_Data        =    0;
  75.  
  76.               MyTags[3].ti_Tag        =    PPCTASKTAG_STARTUP_MSGID;
  77.               MyTags[3].ti_Data        =    0;
  78.  
  79.               MyTags[4].ti_Tag        =    PPCTASKTAG_MSGPORT;
  80.               MyTags[4].ti_Data        =    TRUE;
  81.  
  82.               MyTags[5].ti_Tag        =    TAG_DONE;
  83.  
  84.               if (Task = PPCCreateTask(ElfObject, MyTags))
  85.               {
  86.                 printf("Sending 1000 SYNCHRON messages with a *Body* and wait for each reply...");
  87.  
  88.                 TimerSetAttr(MyTimerObject,TIMERTAG_START);
  89.  
  90.                 for (i=0;i<MSGCOUNT;i++)
  91.                 {
  92.                   PPCWaitPort(M68kPort);
  93.                   while (M68kMsg=PPCGetMessage(M68kPort))
  94.                   {
  95.                     PPCReplyMessage(M68kMsg);
  96.                   }
  97.                 }
  98.                 TimerSetAttr(MyTimerObject,TIMERTAG_STOP);
  99.                 TimerShow(MyTimerObject);
  100.  
  101.                 printf("Waiting for Task Finish Msg...\n");
  102.                 for (;;)
  103.                 {
  104.                   if ((M68kMsg=PPCGetMessage(M68kPort)) == StartupMsg)
  105.                   {
  106.                     printf("Ahh..the expected Startup=Finish Msg was received.\nNow we can savely free all resources.\n");
  107.                     break;
  108.                   }
  109.                   else
  110.                   {
  111.                     printf("Some non replied Msg 0x%lx was found..wait\n",
  112.                            M68kMsg);
  113.                     PPCWaitPort(M68kPort);
  114.                   }
  115.                 }
  116.               }
  117.               else
  118.               {
  119.                 Printf("Could not create PPC task\n");
  120.               }
  121.               PPCFreeVec(StartupData);
  122.             }
  123.             else
  124.             {
  125.               Printf("Could not alloc Startup Data\n");
  126.             }
  127.             PPCDeleteMessage(StartupMsg);
  128.           }
  129.           else
  130.           {
  131.             Printf("Could not create Startup message\n");
  132.           }
  133.           printf("Deleting message port...");
  134.           while (PPCDeletePort(M68kPort) == FALSE);
  135.         }
  136.         else
  137.         {
  138.           Printf("Could not create M68k MsgPort\n");
  139.         }
  140.         printf("Unloading PPC object\n");
  141.         PPCUnLoadObject(ElfObject);
  142.       }
  143.       else
  144.       {
  145.         Printf("Could not load the elfobject\n");
  146.       }
  147.       TimerDeleteObject(MyTimerObject);
  148.     }
  149.     printf("Closing ppc.library\n");
  150.     CloseLibrary(PPCLibBase);
  151.   }
  152.   else
  153.   {
  154.     Printf("Could not open ppc.library v44+\n");
  155.   }
  156. }
  157.  
  158.